package com.sfh.alliance.widget;

import android.app.Activity;
import android.content.Context;
import android.support.annotation.IdRes;
import android.support.v4.app.FragmentActivity;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.sfh.alliance.AnimaUtil;
import com.sfh.alliance.R;

/**
 * 功能描述:
 *
 * @author SunFeihu 孙飞虎
 * @date 2017/9/6
 */
public class BaseTopView extends RelativeLayout implements View.OnClickListener
{
    ImageView iv_colse;
    ImageView iv_title;

    public BaseTopView(Context context) {

        super (context);
        init();
    }

    public BaseTopView(Context context, AttributeSet attrs) {

        super (context, attrs);
        init();
    }

    public BaseTopView(Context context, AttributeSet attrs, int defStyleAttr) {

        super (context, attrs, defStyleAttr);
        init();
    }


    private void init() {
        //
        this.inflate (getContext (), R.layout.base_top_layout, this);

        iv_title = $ (R.id.iv_title);
        iv_colse = $ (R.id.iv_colse);
        iv_colse.setOnClickListener (this);
    }

    public void setTitle(int res){
        iv_title.setImageResource (res);
    }

    private <T extends View> T $(@IdRes int resId) {

        return (T) super.findViewById (resId);
    }

    @Override
    public void onClick(View v) {
        if (v == iv_colse){
           Context context =  getContext ();
            if (context instanceof Activity){
                ((Activity) context).finish ();
            }
        }
    }
}
